package es

import (
	"github.com/olivere/elastic/v7"
)

//  -------------------------------------------- Filter -------------------------------------------
// Term in Filter
func (m *Model) Term(fieldName string, value interface{}) *Model {
	return m.AddFilter(elastic.NewTermQuery(fieldName, value))
}

// Terms in Filter
func (m *Model) Terms(fieldName string, values ...interface{}) *Model {
	return m.AddFilter(elastic.NewTermsQuery(fieldName, values...))
}

// Match in Filter
func (m *Model) Match(fieldName string, value interface{}) *Model {
	return m.AddFilter(elastic.NewMatchQuery(fieldName, value))
}

// MatchPhrase in Filter
func (m *Model) MatchPhrase(fieldName string, value interface{}) *Model {
	return m.AddFilter(elastic.NewMatchPhraseQuery(fieldName, value))
}

// Range in Filter
func (m *Model) Range(fieldName string, rangeOptions ...RangeOption) *Model {
	r := elastic.NewRangeQuery(fieldName)
	for _, rangeOption := range rangeOptions {
		rangeOption(r)
	}
	return m.AddFilter(r)
}

// Exist in Filter
func (m *Model) Exist(fieldName string) *Model {
	return m.AddFilter(elastic.NewExistsQuery(fieldName))
}
